<script setup>
import http from "./utils/http/";


function getInfo() {
  http.get("/get").then((response) => {
    console.log(response);
  })
}

function getInfoParam() {
  http.get("/get", {
    params: {
      id: 1,
      username: 'hangman'
    }
  }).then((response) => {
    console.log(response);
  })
}

function postInfo() {
  http.post("/post").then(response => {
    console.log(response);
  })
}

function postInfoParam() {
  //数据会自动转为json
  http.post("/post", {
    id: 2,
    username: 'hangman',
    age: 18
  }).then(response => {
    console.log(response);
  })
}

function delay2() {
  http.get("/delay/2").then((response) => {
    console.log(response);
  }).catch((error) => {
    console.log(error.message);
  })
}
</script>

<template>
  <button @click="getInfo">GET 请求</button>
  <button @click="getInfoParam">GET 请求参数</button>
  <button @click="postInfo">POST 请求</button>
  <button @click="postInfoParam">POST 请求参数</button>
  <button @click="delay2">delay 2s</button>
</template>

<style scoped>

</style>
